home *** CD-ROM | disk | FTP | other *** search
/ How Would You Survive? / How Would You Survive (1995)(Grolier)[Mac-PC].iso / pc / vindex.dir / 00040_Script_aTopicMenu < prev    next >
Text File  |  1995-09-06  |  8KB  |  208 lines

  1. --òò aTopicMenu
  2. --òò This object represents an entry in the Alabetical Index System
  3. --òò In otherwords we need to create one of these objects per
  4. --òò Letter in the alphabet. This object in turn manages a sub-menu
  5. --òò of entries associated with the Letter. Each sub-menu entry
  6. --òò manages a list of links to locations in the subject screens
  7. --òò of the title.
  8. --òò REV 8 / 4 / 51
  9. property pHilightCast, pSprite , pDefaultCast , pRange┬
  10.        , pRefLink , pLeftEntries, pRightEntries , pEndOFLine  , pLineSpace
  11. on birth me , startCast , stopCast , theSprite , theDefaultCast┬
  12.             , functionCast ,iconCast  ,numLeftEntries, newRightEntries
  13.   setTopicMenuParameters me , numLeftEntries, newRightEntries
  14.   set pLineSpace = 25
  15.   set pDefaultCast = theDefaultCast 
  16.   if (startCast) then
  17.     set pHilightCast = startCast 
  18.   else
  19.     set pHilightCast = pDefaultCast
  20.   end if
  21.   set pRange = stopCast - startCast + 1
  22.   set pSprite = theSprite
  23.   
  24.   set refCountMax = numLeftEntries + newRightEntries 
  25.   set refCount = 1
  26.   set pRefLink = []
  27.   set pEndOFLine = FALSE
  28.   set refLinkClass = the number of cast "aRefLink"
  29.   repeat while (refCount <= refCountMax)
  30.     setAt( pRefLink ,refCount, birth (script refLinkClass, iconCast + refCount - 1 ,40┬
  31.         ,1 ,functionCast))
  32.     set refCount = refCount + 1
  33.   end repeat
  34.   
  35.   return me
  36. end
  37.  
  38. on setTopicMenuParameters me , numLeftEntries, newRightEntries
  39.   set pRightEntries = newRightEntries
  40.   set pLeftEntries = numLeftEntries
  41. end
  42.  
  43. on setTopicMenu me
  44.   if (pSprite > 0) then
  45.     set the castNum of sprite pSprite = pHilightCast 
  46.   else
  47.     set the castNum of sprite pSprite = pDefaultCast
  48.   end if
  49. end
  50.  
  51. on setTopicHiLight me , theOffset
  52.   if (pRightEntries and rollover(41)) then
  53.     -- right entry processing
  54.     set topicOffset =  theOffset/pLineSpace
  55.     if (topicOffset <= pRange) then 
  56.       set the castNum of sprite pSprite = pHilightCast + topicOffset - 1 + pLeftEntries
  57.     end if
  58.   else
  59.     -- left entry processing
  60.     set topicOffset =  theOffset/pLineSpace
  61.     if (topicOffset <= pRange) then 
  62.       set the castNum of sprite pSprite = pHilightCast + topicOffset - 1 
  63.     end if 
  64.   end if
  65. end
  66.  
  67. --òò Ref Link handlers
  68. on selectTopicFromMenu me,theOffset
  69.   if (theOffset > 62) then 
  70.     set theOffset = theOffset - 62
  71.     set topicOffset =  (theOffset/pLineSpace) + 1
  72.     --put theOffset , topicOffset
  73.     if (pRightEntries and rollover(41)) then
  74.       -- right entry processing
  75.       if (topicOffset > 0 and topicOffset <= pRightEntries) then
  76.         set thisLink = getAt(pRefLink,topicOffset + pLeftEntries) 
  77.       end if
  78.     else
  79.       -- left entry processing
  80.       if (topicOffset > 0 and topicOffset <= pLeftEntries) then
  81.         set thisLink = getAt(pRefLink,topicOffset) 
  82.       end if
  83.     end if
  84.     showRefLinkIcon(thisLink) 
  85.   end if
  86. end
  87.  
  88. on clickRefLink me , theOffset , horzPos , vertPos
  89.   set pEndOFLine = FALSE
  90.   --put vertPos ,horzPos
  91.   --set thisLink = getAt(pRefLink,1)
  92.   --clickRefLink(thisLink , theOffset)
  93.   set thisCast = the castNum of sprite 40
  94.   set thisStr = the scriptText of cast thisCast
  95.   set thisLength = length(thisStr)
  96.   set strCount = 3
  97.   set commaPos1 = getCommaPos (me, thisStr , strCount , thisLength)
  98.   set commaPos2 = getCommaPos (me, thisStr , commaPos1 + 1, thisLength)
  99.   set commaPos3 = getCommaPos (me, thisStr , commaPos2 + 1, thisLength)
  100.   set commaPos4 = getCommaPos (me, thisStr , commaPos3 + 1, thisLength)
  101.   if (getRecPos (me, thisStr , 3 , commaPos1 ) = 0) then
  102.     -- this is simple (one ref) reference
  103.     --beep 1
  104.     --put 1
  105.     do getFunctionStr (me, thisStr , commaPos4 , thisLength ) 
  106.   else
  107.     -- test if click is inside of rect
  108.     set pEndOFLine = FALSE
  109.     set startStr = 2
  110.     set beepCount = 1
  111.     repeat while (pEndOFLine = FALSE)
  112.       --testClick me,commaPos1,commaPos2,commaPos3,commaPos4 , ┬
  113.           thisStr , thisLength , horzPos , vertPos
  114.       if (testClick(me,startStr,commaPos1,commaPos2,commaPos3 ┬
  115.                  , thisStr , thisLength, horzPos , vertPos)) then 
  116.         -- get function
  117.         set pEndOFLine = TRUE
  118.         --beep beepCount
  119.         --put beepCount
  120.         do getFunctionStr (me, thisStr , commaPos4 , thisLength )
  121.       else
  122.         -- move past function
  123.         set semiColPos = getSemiCol  (me, thisStr , commaPos4 + 1 , thisLength)
  124.         set commaPos1 = getCommaPos (me, thisStr , semiColPos + 1 , thisLength)
  125.         set commaPos2 = getCommaPos (me, thisStr , commaPos1 + 1, thisLength)
  126.         set commaPos3 = getCommaPos (me, thisStr , commaPos2 + 1, thisLength)
  127.         set commaPos4 = getCommaPos (me, thisStr , commaPos3 + 1, thisLength)
  128.         set startStr = semiColPos
  129.         set beepCount = beepCount + 1
  130.       end if 
  131.     end repeat
  132.   end if
  133. end
  134.  
  135. on clearRefLinkIcon me
  136.   if (not(pRefLink = []) ) then
  137.     set thisLink = getAt(pRefLink,1)
  138.     clearRefLinkIcon(thisLink) 
  139.   end if
  140. end
  141.  
  142. on getSemiCol  me , thisStr , strCount , thisLength
  143.   --òò This handler returns the position of the next comma, or the end of the string
  144.   set thisChar = chars(thisStr,strCount,strCount)
  145.   if (thisChar = "%") then set pEndOFLine = TRUE
  146.   repeat while (not(thisChar = ";") and strCount < thisLength) 
  147.     set strCount = strCount + 1
  148.     set thisChar = chars(thisStr,strCount,strCount)
  149.     if (thisChar = "%") then set pEndOFLine = TRUE
  150.   end repeat
  151.   return strCount
  152. end
  153.  
  154. on getCommaPos me , thisStr , strCount , thisLength
  155.   --òò This handler returns the position of the next comma, or the end of the string
  156.   set thisChar = chars(thisStr,strCount,strCount)
  157.   if (thisChar = "%") then set pEndOFLine = TRUE
  158.   repeat while (not(thisChar = ",") and strCount < thisLength) 
  159.     set strCount = strCount + 1
  160.     set thisChar = chars(thisStr,strCount,strCount)
  161.     if (thisChar = "%") then set pEndOFLine = TRUE
  162.   end repeat
  163.   return strCount
  164. end
  165.  
  166. on getRecPos me , thisStr , strCount , thisLength
  167.   set intCount = strCount
  168.   set thisChar = chars(thisStr,strCount,strCount)
  169.   repeat while (not(thisChar = ",") and strCount < thisLength) 
  170.     set strCount = strCount + 1
  171.     set thisChar = chars(thisStr,strCount,strCount)
  172.   end repeat
  173.   return (chars (thisStr , intCount , strCount - 1))
  174. end
  175.  
  176. on getFunctionStr me, thisStr , strCount , thisLength
  177.   set intCount = strCount
  178.   set thisChar = chars(thisStr,strCount,strCount)
  179.   repeat while (not(thisChar = ";") and strCount < thisLength) 
  180.     set strCount = strCount + 1
  181.     set thisChar = chars(thisStr,strCount,strCount)
  182.   end repeat
  183.   return (chars (thisStr , intCount + 1 , strCount - 1))
  184. end
  185.  
  186. on testClick me,commaPos1,commaPos2,commaPos3,commaPos4 , thisStr , thisLength , horzPos , vertPos
  187.   set topPos = getRecPos (me , thisStr , commaPos1 + 1 , thisLength)
  188.   set leftPos =  getRecPos (me , thisStr , commaPos2 + 1 , thisLength)
  189.   set bottomPos =  getRecPos (me , thisStr , commaPos3 + 1 , thisLength)
  190.   set rightPos =  getRecPos (me , thisStr , commaPos4 + 1 , thisLength)
  191.   --  put "T"&&topPos
  192.   --  put "L"&&leftPos
  193.   --  put "B"&&bottomPos
  194.   --  put "R"&&rightPos&&RETURN
  195.   if ((topPos < vertPos) and (bottomPos > vertPos) and ┬
  196.          (leftPos < horzPos) and (rightPos > horzPos)) then 
  197.     -- we have a click within this rect
  198.     return TRUE
  199.   else
  200.     return FALSE
  201.   end if
  202. end
  203.  
  204. on reset me 
  205.   --put pSprite, pDefaultCast
  206.   set the castNum of sprite pSprite = pDefaultCast
  207.   clearRefLinkIcon me
  208. end